using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Genghis;
using TeleTwitter.Lib;

namespace TeleTwitter
{
    public partial class DirectMessageForm : Form
    {
        BrowserController _controller = new BrowserController();
        WindowSerializer _windowSerializer = null;
        private User _targetUser;
        private User _currentUser;


        public DirectMessageForm()
        {
            InitializeComponent();

            _windowSerializer = new WindowSerializer(this);

        }


        private void DirectMessageForm_Load(object sender, EventArgs e)
        {
            InitControls();   
        }

        private void InitControls()
        {
            webBrowser1.ObjectForScripting = _controller;
            webBrowser1.DocumentText = _controller.GetDirectMessageDocument();
        }

        private void InvokeScript(string scriptName, string input)
        {
            InvokeScript(scriptName, new object[] { input });
        }

        private void InvokeScript(string scriptName, object[] args)
        {
            webBrowser1.Document.InvokeScript(scriptName, args);
        }

        public User TargetUser
        {
            get { return _targetUser; }
            set { 
                _targetUser = value; 
                
            }
        }

        public User CurrentUser
        {
            get { return _currentUser; }
            set { 
                _currentUser = value;
                InvokeScript("setCurrentUser", "<img src='" + value.ProfileImageUrl + "'>");
            }
        }

        public void AddStatus(Status statusMessage)
        {

            InvokeScript("setContents", StatusFormatter.FormatStatusHtml(statusMessage));

        }

        private void textDirectMessage_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                
                InvokeScript("setContents", "<div id=\"tlitem\">" + textDirectMessage.Text + "</div><span id=\"tlcreated\"><img src=\"" + _currentUser.ProfileImageUrl + "\"></span>");

                textDirectMessage.Clear();

            }
        }





    }
}